<template>
    <div class='integral'>
        <div class="container">
            <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" class="search-con">
                <el-form-item label="用户账号" prop="key_name" style="margin-right:25px;">
                    <el-input v-model="queryParams.key_name" placeholder="用户ID/账号" clearable size="small" />
                </el-form-item>
                <el-form-item label="用户昵称" prop="key_name" style="margin-right:25px;">
                    <el-input v-model="queryParams.key_name" placeholder="用户昵称" clearable size="small" />
                </el-form-item>
                <el-form-item label="会员等级" prop="key_name" style="margin-right:25px;">
                    <el-input v-model="queryParams.key_name" placeholder="会员等级" clearable size="small" />
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">查询</el-button>
                    <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
                    <el-button type="warning" icon="el-icon-download" size="mini" @click="handleExport" v-hasPermi="['customer:manage:export']">导出
                    </el-button>
                </el-form-item>
            </el-form>
            <el-row :gutter="10" class="mb8">
                <el-col :span="22">
                    <el-button type="primary" icon="el-icon-edit" size="mini" @click="curRow={};title = '创建客户';handleShow = 'add';" v-hasPermi="['customer:manage:add']">
                        批量修改</el-button>
                </el-col>
                <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
            </el-row>
            <el-table border v-loading="loading" :data="tableList" ref="tableList" v-tableHeight :height="tableList &&tableList.length > 0 ? '900px' : '120px'"
                @selection-change="handleSelectionChange" @row-click="toggleSelection">
                <el-table-column type="selection" width="55" align="center" fixed="left" />
                <el-table-column label="用户ID" align="center" prop="mobile" />
                <el-table-column label="用户账号" align="center" prop="mobile" />
                <el-table-column label="用户昵称" align="center" prop="mobile" />
                <el-table-column label="会员等级" align="center" prop="mobile" />
                <el-table-column label="可用蔚蓝币" align="center" prop="mobile" />
                <el-table-column label="历史蔚蓝币" align="center" prop="mobile" />
                <el-table-column label="成长值" align="center" prop="mobile" />
                <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                    <template slot-scope="scope">
                        <el-button size="mini" type="text" @click="handleBtn(scope.row,'currency')" v-hasPermi="['customer:manage:edit']">
                            蔚蓝币明细
                        </el-button>
                        <el-button size="mini" type="text" @click="handleBtn(scope.row,'growth')" v-hasPermi="['customer:manage:edit']">
                            成长值明细
                        </el-button>
                        <el-button size="mini" type="text" icon="el-icon-edit" @click="handleEdit(scope.row)" v-hasPermi="['customer:manage:edit']">
                            修改数值
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
            <pagination v-show="pageCount > 0" :pageCount="pageCount" :page.sync="queryParams.page" :limit.sync="queryParams.limit" @pagination="getList" />

            <detail v-if="handleShow=='currency' || handleShow=='growth'" :handleShow="handleShow" @close="handleShow=''" />

            <el-dialog title="修改数值" visible v-if="handleShow=='edit'" @close="close()" width="600px" append-to-body :close-on-click-modal="false">
                <el-form ref="form" :model="form" :rules="rules" label-width="120px" v-loading="formLoading">
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="调整蔚蓝币" prop="sex">
                                <el-radio-group v-model="form.sex">
                                    <el-radio v-for="dict in radioList" :key="dict.dictValue" :label="Number(dict.dictValue)">
                                        {{ dict.dictLabel }}
                                    </el-radio>
                                </el-radio-group>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="" prop="price" label-width="0px">
                                <el-input style="width:200px;" v-model="form.price" @keyup.native="form.price=handleNum(form.price)" placeholder="请输入调整数目">
                                    <template slot="append">个</template>
                                </el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="调整成长值" prop="sex">
                                <el-radio-group v-model="form.sex">
                                    <el-radio v-for="dict in radioList" :key="dict.dictValue" :label="Number(dict.dictValue)">
                                        {{ dict.dictLabel }}
                                    </el-radio>
                                </el-radio-group>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="" prop="price" label-width="0px">
                                <el-input style="width:200px;" v-model="form.price" @keyup.native="form.price=handleNum(form.price)" placeholder="请输入调整数目">
                                    <template slot="append">个</template>
                                </el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="24">
                            <el-form-item label="备注" prop="remarks">
                                <el-input style="width: 360px;" v-model="form.remarks" type="textarea" rows="4" placeholder="请输入备注"></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                </el-form>
                <span slot="footer" class="dialog-footer">
                    <el-button @click="close()">取 消</el-button>
                    <el-button type="primary" @click="submit" :disabled="formLoading">确 定</el-button>
                </span>
            </el-dialog>
        </div>
    </div>
</template>
<script>
import throttle from 'lodash.throttle'
import detail from "./integralDetails.vue"
export default {
    name: 'integral',
    components: {
        detail
    },
    data() {
        return {
            showSearch: true,
            loading: false,
            total: 0,
            pageCount: 0,
            queryParams: {
                page: 1,
                limit: 20,
                key_name: null,
            },
            tableList: [
                {}
            ],
            selectData: [],
            handleShow: "",
            formLoading: false,
            form: {

            },
            rules: {
                sex: [{ required: true, message: '请选择', trigger: 'change' }],
                price: [{ required: true, message: '请输入调整数目', trigger: 'blur' }],

            },
            radioList: [
                {
                    dictLabel: '增加',
                    dictValue: 1
                },
                {
                    dictLabel: '减少',
                    dictValue: 0
                },
            ],
        }
    },
    created() {
        this.getList()
    },
    methods: {
        getList() {
            // this.loading = true;
            // getHospLists(this.queryParams).then(res => {
            //     this.tableList = res.data ? res.data.lists : [];
            //     this.pageCount = res.data.pageCount;
            //     this.loading = false;
            // });
        },
        handleBtn(row, type) {
            this.handleShow = type
        },
        handleEdit(row) {
            this.handleShow = "edit"
        },
        close() {
            this.form = {}
            this.handleShow = ""
        },
        submit: throttle(function () {
            this.$refs.form.validate((valid) => {
                if (valid) {
                    // this.formLoading = true;
                    // this.form.new_pass = md5(this.form.new_pass)
                    // retrievePass(this.form).then(res => {
                    //     this.msgSuccess("操作成功！");
                    //     this.close()
                    //     this.formLoading = false;
                    // }).catch(() => {
                    //     this.formLoading = false;
                    // })
                }
            })
        }, 1000, { trailing: false }),
        toggleSelection(row) {
            this.$refs.tableList.toggleRowSelection(row);
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
            this.selectData = selection;
        },
        /** 导出按钮操作 */
        handleExport() {
            const queryParams = this.queryParams;
            this.$confirm('是否确认导出所有数据项?', '警告', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(function () {
                // return exportBanner(queryParams);
            }).then((response) => {
                // this.download(response.msg);
            });
        },
        handleQuery() {
            this.queryParams.page = 1;
            this.getList();
        },
        resetQuery() {
            this.resetForm("queryForm");
            this.handleQuery();
        },
    },
}

</script>
<style scoped lang='scss'>
</style>